/**
 * 
 */
package z.tool.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author auzll@163.com
 */
public class PropertiesLoader {
    private static final Log LOG = LogFactory.getLog(PropertiesLoader.class);
    
    public static boolean hasProperyKey(String fileName, String key) {
        Properties properties = loadProperties(fileName);
        return null != properties ? properties.containsKey(key) : false;
    }
    
    public static String getPropery(String fileName, String key) {
        Properties properties = loadProperties(fileName);
        return null != properties ? ZUtils.trimStringNull(properties.getProperty(key)) : null;
    }
    
    public static Properties loadProperties(String fileName) {
        Properties properties = new Properties();
        
        InputStream is = InputStreamLoader.loadInputStream(fileName);
        if (null != is) {
            try {
                properties.load(is);
            } catch (IOException e) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("method:loadProperties", e);
                }
            }
            
            try {
                is.close();
            } catch (IOException e) {
            }
        }
        
        return properties;
    }
}
